const watchObj = ['watchStorage', 'themePayStorage', 'rewardStorage']

let findWatch = (key) => {
  return watchObj.find(item => item === key)
}
export const wachtStorage = (key, newVal) => {
  if (findWatch(key)) {
    console.log('执行了数据监听+++++++++++++++++++++++', key, newVal)
    let newStorageEvent = document.createEvent('StorageEvent')
    const storage = {
      setItem: (k, val) => {
        sessionStorage.setItem(k, val)
        // 初始化创建的事件
        newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null)
        // 派发对象
        window.dispatchEvent(newStorageEvent)
      }
    }
    return storage.setItem(key, newVal)
  }
}
